package com.rede.didiok.user.service.impl;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rede.didiok.common.enums.StatusEnum;
import com.rede.didiok.common.utils.PageUtils;
import com.rede.didiok.common.utils.Query;
import com.rede.didiok.user.dao.UserAccountDao;
import com.rede.didiok.user.entity.UserAccountEntity;
import com.rede.didiok.user.service.UserAccountService;


@Service("userAccountService")
public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAccountEntity> implements UserAccountService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserAccountEntity> page = this.page(
                new Query<UserAccountEntity>().getPage(params),
                new QueryWrapper<UserAccountEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 根据来源编号与第三方uid查询
     *
     * @param source
     * @param uuid
     * @return
     */
    @Override
    public UserAccountEntity queryRelation(String source, String uuid) {
        return getOne(
                new LambdaQueryWrapper<UserAccountEntity>()
                        .eq(UserAccountEntity::getSource, source)
                        .eq(UserAccountEntity::getSocialUid, uuid)
                        .eq(UserAccountEntity::getStatus, StatusEnum.ENABLE)
        );
    }

}